package com.xiaotu;
//懒汉式
public class lazyMan {
    private lazyMan(){
        System.out.println(Thread.currentThread().getName()+"ok");
    }
    private volatile static lazyMan lazyMan;//避免指令重排

    public static lazyMan getLazyMan(){
        if(lazyMan==null){
            synchronized (lazyMan.class){
                if(lazyMan==null){
                    lazyMan=new lazyMan();
                }
            }
        }
        return lazyMan;
    }

    public static void main(String[] args) {
        for(int i = 0;i<10;i++){
            new Thread(()->{lazyMan.getLazyMan();}).start();
        }
    }
}
